<template>
    <vol-box v-model="model" :padding="30" title="发送入职审批" :width="500" :height="250">
        <el-form :model="row" label-width="80px">
            <el-form-item label="部门">
                <el-select v-model="row.departName" :disabled="true">
                    <el-option v-for="item in departlist" :key="item.departId" :label="item.departName"
                        :value="item.departName" @click="position(item.departId)" />
                </el-select>
            </el-form-item>
            <el-form-item label="职位">
                <el-select v-model="row.positionName" :disabled="true">
                    <el-option v-for="item in positonList" :label="item.positionName"
                        :value="item.positionName"></el-option>
                    <!-- 可根据实际情况添加更多职位选项 -->
                </el-select>
            </el-form-item>
            <el-form-item label="员工姓名">
                <el-select v-model="row.employsName" :disabled="true">
                    <el-option v-for="item in emploList" :label="item.employsName" :value="item.employsName"></el-option>
                    <!-- 可根据实际情况添加更多员工姓名选项 -->
                </el-select>
            </el-form-item>
            <el-form-item label="上级负责">
                <el-select v-model="row.leaderName" :disabled="true">
                    <el-option label="孟盘龙" value="孟盘龙" />
                    <el-option label="刘永刚" value="刘永刚" />
                    <el-option label="赵秋实" value="赵秋实" />
                    <el-option label="于晋哲" value="于晋哲" />
                    <el-option label="牛骞若" value="牛骞若" />
                    <el-option label="赵思彤" value="赵思彤" />
                </el-select>
            </el-form-item>
            <el-form-item label="入职日期">
                <el-date-picker v-model="row.onboardingDate" type="date" :disabled="true"></el-date-picker>
            </el-form-item>
            <el-form-item label="备注">
                <el-input v-model="row.remark" type="textarea" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="add()">提交审核</el-button>
            </el-form-item>
        </el-form>
    </vol-box>
</template>
<script>
import axios from '@/api/http'
import { ElMessage } from 'element-plus'
import { defineComponent, defineAsyncComponent } from "vue";
export default defineComponent({
    components: {
        VolBox: defineAsyncComponent(() => import("@/components/basic/VolBox.vue"))
    },
    data() {
        return {
            row: {
                "onboardTransactId": "",
                "departName": "",
                "positionName": "",
                "employsName": "",
                "leaderName": "",
                "onboardingDate": "2024-08-26",
                "remark": "",
                "approvalType": 0,
                "approvalName": "",
                "createName": "",
                "createTime": "2024-08-26",
                "updateName": "string",
                "updateTime": "2024-08-26",
                "isDel": 0
            },
            model: false,
            rid: null,
            departlist: [],
            positonList: [],
            emploList: []
        };

    },

    methods: {

        open(row) {
            this.row.onboardTransactId = row.OnboardTransactId;
            this.row.departName = row.DepartName;
            this.row.positionName = row.PositionName;
            this.row.employsName = row.EmploysName;
            this.row.leaderName = row.LeaderName;
            this.row.onboardingDate = row.OnboardingDate;
            this.row.remark = row.Remark;
            this.row.approvalType = row.ApprovalType;
            this.row.approvalName = row.ApprovalName;
            this.row.createName = row.CreateName;
            this.row.createTime = row.CreateTime;
            this.row.updateName = row.UpdateName;
            this.row.updateTime = row.UpdateTime;
            this.row.isDel = row.IsDel;
            this.model = true;
            console.log(this.row);
        },
        add() {
            axios.post('/personnel-write/api/onboardtransact/Sendonboardapproval?type=' + this.row.approvalType, this.row)
                .then((res) => {
                    if (res > 0) {  // 注意这里修改为 res.data
                        ElMessage.success('提交成功');
                        this.model = false;

                    } else {
                        ElMessage.error('添加失败，请检查数据');
                    }
                })
        },
        callParent() {
            this.$emit('parentCall', $parent => {
                //$parent就是生成页面的对象，比如可以调用页面刷新，可获取的属性与方法见【生成页面文档】,$parent.xxx直接调用
                //调用刷新
                $parent.search();
                //获取所有选中的行数据
                // $parent.getSelectRows();
                this.$message.success('调用了刷新')
            })
        },
        depart() {
            axios.get('/personnel-write/api/onboardtransact/GetDepartments')
                .then(res => {
                    this.departlist = res;
                })

        },
        position(departId) {
            axios.get('/personnel-write/api/onboardtransact/GetPositions?departId=' + departId)
                .then(res => {
                    this.positonList = res;
                    console.log(res)
                })
        },
        emplop() {
            axios.get('/personnel-write/api/onboardtransact/GetEmploysregistereds')
                .then(res => {
                    this.emploList = res;
                })
        }

    },
    mounted() {
        this.row
        this.depart();
        this.position();
        this.emplop();
    }

})
</script>